﻿using Prism.Commands;
using StarryEdge.Core;
using StarryEdge.Core.Parameter;
using StarryEdge.Parameter;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace StarryEdge.Menu.SettingSystem.ViewModels
{
    public class SystemConfigParameterViewModel
    {
        private IDialogHost _dialogHost;
        public SystemConfigParameter ConfigParameter { get; set; }
        public SystemConfigParameterViewModel(IDialogHost dialogHost, ISystemConfigParameter systemConfigParameter)
        {
            _dialogHost = dialogHost;
            ConfigParameter = (SystemConfigParameter)systemConfigParameter;
        }

        public DelegateCommand SaveParameter => new DelegateCommand(() =>
        {
            try
            {
                ConfigParameter.Save();
            }
            catch (Exception ex)
            {
                _dialogHost.DialogShow($"{nameof(SystemConfigParameterViewModel)}\r\n保存异常：{ex}", Core.Enums.LogLevel.Error, hostDialog:Core.Enums.PopUpTypes.Global);
                return;
            }
            _dialogHost.DialogShow($"{nameof(SystemConfigParameterViewModel)}\r\n保存成功", Core.Enums.LogLevel.Success, hostDialog: Core.Enums.PopUpTypes.Global);
        });
    }
}
